#include "login.h"
#include "ui_login.h"
#include <QFile>
#include <QTextStream>

Login::Login(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::Login)
{
    m_ui->setupUi(this);
    QImage image_bul("../images/bulle.jpg");
    QImage image_bul2("../images/bulle2.jpg");
    QImage image_twittoz("../images/twittoz.jpg");
    QImage image_twittoz2("../images/twittoz.png");


    m_ui->bulle1->setPixmap(QPixmap::fromImage(image_bul));
    m_ui->bulle2->setPixmap(QPixmap::fromImage(image_bul2));
    m_ui->twittoz->setPixmap(QPixmap::fromImage(image_twittoz));
    m_ui->twittoz2->setPixmap(QPixmap::fromImage(image_twittoz2));
    QObject::connect (this, SIGNAL(accepted()), this, SLOT(login_accepted()));
    QObject::connect (this, SIGNAL(accepted()), parent, SLOT(loadAuth()));

}

void Login::login_accepted()
{
    QFile file("../.auth.tw");
     if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
         return;
     file.flush();
     QTextStream out(&file);
     out << m_ui->lineEdit->text() << ":" << m_ui->lineEdit_2->text();
     file.close();
}

Login::~Login()
{
    delete m_ui;
}

void Login::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
